package com.tanhua.locationmanager.controller;

import com.tanhua.domain.db.SurveyQuestion;
import com.tanhua.locationmanager.service.QuestionService;
import com.tanhua.vo.QuestionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


/**
 * 题目控制器
 * 处理题目相关
 * @author Huo
 * @date 2021/07/17 19:07:53
 */
@RestController
@RequestMapping("/question")
public class QuestionController {


    @Autowired
    private  QuestionService questionService;

    @GetMapping(value = "/{paperId}/findQuestions",name = "分页查询具体套题的全部题目")
    public ResponseEntity<?> queryByPage(@PathVariable("paperId") Integer paperId,@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "5") Integer pagesize) {
        return questionService.queryByPage(paperId,page,pagesize);
    }

    @PostMapping(value = "/saveQuestion",name = "保存试题")
    public ResponseEntity<?> saveQuestion(@RequestBody QuestionVo questionVo) {
        return questionService.saveQuestion(questionVo);
    }


    @GetMapping(value = "/findById/{id}",name = "根据id查询试卷试题")
    public ResponseEntity<?> queryQuestionById(@PathVariable("id") Integer questionId) {
        return questionService.queryQuestionById(questionId);
    }

    @PutMapping(name = "更改试卷试题")
    public ResponseEntity<?> update(@RequestBody QuestionVo questionVo) {
        // TODO: 2021/7/18 修改霍
        return questionService.update(questionVo);
    }

    @GetMapping(value = "/{questionId}/findOptionsByQuestionId",name = "根据问题id查询所有选项")
    public ResponseEntity<?> findOptionsByQuestionId(@PathVariable("questionId") Integer questionId) {
        return questionService.findOptionsByQuestionId(questionId);
    }

    @DeleteMapping(value = "/{questionId}",name = "根据问题id删除问题及其所有选项")
    public ResponseEntity<?> deleteQuestion(@PathVariable("questionId") Integer qid) {
        return questionService.deleteQuestion(qid);
    }
}
